package com.hnhd.eorder.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * 封装数据库操作
 * 
 * @author dengbiao
 * 
 */
/**
 * 封装数据库操作
 * 
 * @author dengbiao
 * 
 */
public class SQLUtil {

	/**
	 * 数据库操作对象
	 */
	private static DatabaseHelper dbHelper;

	/**
	 * 可读数据库
	 */
	private static SQLiteDatabase sqliteDatabaseReadable;

	/**
	 * 可写数据库
	 */
	private static SQLiteDatabase sqliteDatabaseWritable;



	public static final String DISH = "T_DISH";
	public static final String DISH_ID = "id";
	public static final String DISH_NAME = "name";
	public static final String DISH_BRIEF = "brief";
	public static final String DISH_LARGEPIC = "largePic";
	public static final String DISH_MEDIUMPIC = "mediumPic";
	public static final String DISH_SMALLPIC = "smallPic";
	public static final String DISH_MODEL = "model";
	public static final String DISH_NORM = "norm";
	public static final String DISH_PRICE = "price";
	public static final String DISH_ISGUQING = "isGuqing";
	public static final String DISH_REMAIN = "remain";
	
	public static final String ORDERITEM = "T_ORDERITEM";
	public static final String ORDERITEM_ID = "id";
	public static final String ORDERITEM_ORDERID = "orderId";
	public static final String ORDERITEM_DISHID = "dishId";
	public static final String ORDERITEM_NUMBER = "number";
	public static final String ORDERITEM_PRICE = "price";
	public static final String ORDERITEM_DISCOUNT = "discount";
	public static final String ORDERITEM_REMARKS = "remarks";
	public static final String ORDERITEM_STATUS = "status";
	public static final String ORDERITEM_ISPRINT = "isPrint";
	
	public static final String ORDER = "T_ORDER";
	public static final String ORDER_ID = "id";
	public static final String ORDER_TABLEID = "tableId";
	public static final String ORDER_NUMBER = "number";
	public static final String ORDER_SERVER = "server";
	public static final String ORDER_CASHIER = "cashier";
	public static final String ORDER_PRICE = "price";
	public static final String ORDER_DISCOUNT = "discount";
	public static final String ORDER_STATUS = "status";
	public static final String ORDER_REMARKS = "remarks";
	public static final String ORDER_ORDERTIME = "orderTime";
	public static final String ORDER_ENDTIME = "endTime";
	
	public static final String DISHTYPE = "T_DISHTYPE";
	public static final String DISHTYPE_DISHID = "dishID";
	public static final String DISHTYPE_TYPEID = "typeID";
	
	public static final String TYPE = "T_FOODTYPE";
	public static final String TYPE_ID = "id";
	public static final String TYPE_NAME = "name";
	
	public static final String TABLE = "T_TABLE";
	public static final String TABLE_ID = "id";
	public static final String TABLE_NAME = "name";
	public static final String TABLE_ROOMID = "roomID";
	public static final String TABLE_BRIEF = "brief";
	public static final String TABLE_NUMBER = "number";
	public static final String TABLE_STATUS = "status";
	
	public static final String ROOM = "T_ROOM";
	public static final String ROOM_ID = "id";
	public static final String ROOM_NAME = "name";
	public static final String ROOM_BRIEF = "brief";
	public static final String ROOM_TABLENUM = "tableNum";
	public static final String ROOM_HASAIRCONDITION = "hasAircondition";
	public static final String ROOM_HASBATHROOM = "hasBathroom";
	public static final String ROOM_HASMAHJONG = "hasMahjong";
	

	/**
	 * 关闭数据库
	 */
	public static void closeDatabase() {
		if (sqliteDatabaseWritable != null)
			sqliteDatabaseWritable.close();
		if (sqliteDatabaseReadable != null)
			sqliteDatabaseReadable.close();
		dbHelper.close();
	}

	/**
	 * 获得可读的数据库访问对象
	 */
	public static SQLiteDatabase getReadableDatabase() {
		if (sqliteDatabaseReadable == null) {
			sqliteDatabaseReadable = dbHelper.getReadableDatabase();
		}
		return sqliteDatabaseReadable;
	}

	/**
	 * 获得可写的数据库访问对象
	 */
	public static SQLiteDatabase getWritableDatabase() {
		if (sqliteDatabaseWritable == null) {
			sqliteDatabaseWritable = dbHelper.getWritableDatabase();
		}
		return sqliteDatabaseWritable;
	}

	/**
	 * 利用构造函数初始化{@link DatabaseHelper}
	 * 
	 * @param context
	 */
	public SQLUtil(Context context) {
		dbHelper = new DatabaseHelper(context);
	}

	public static Cursor query(String table, String[] columns,
			String selection, String[] selectionArgs, String groupBy,
			String having, String orderBy) {
		getReadableDatabase();
		Cursor cursor = sqliteDatabaseReadable.query(table, columns, selection,
				selectionArgs, groupBy, having, orderBy);
		return cursor;
	}

	

	

	

}
